# To change this template, choose Tools | Templates
# and open the template in the editor.

module LoaderHelper
  def loading(div_id,html_options = { })
    html_options.merge!(
      :only_img => false
    ) if html_options[:only_img].blank?
    html_options.merge!(
      :image_type => 'normal'
    ) if html_options[:image_type].blank?
    html_options.merge!(
      :height => "' + $(\"#{html_options[:height_from]}\").getHeight() + '"
    ) if html_options[:height_from].present?
    html_options.merge!(
      :width => "' + $(\"#{html_options[:width_from]}\").getWidth() + '"
    ) if html_options[:width_from].present?
    html_options[:only_img] ? (
      "$('#{div_id}').update('#{image_tag "loader/#{html_options[:image_type]}.gif"}');"
    ) : (
      html_options = {:height => '98%',:width => '100%'}.merge(html_options)      
      "$('#{div_id}').update('<table class=\"short_loader\" width=\"#{html_options[:width]}\"  height=\"#{html_options[:height]}\"><tr><td align=\"center\" valign=\"middle\">#{image_tag "loader/#{html_options[:image_type]}.gif" , :title => 'loading', :alt => 'loading'}</td></tr></table>');"
    )
  end
  
  def nano_loading(div_id,html_options = { })
    loading div_id, { :image_type => 'nano'}.merge(html_options)
  end
  
  def small_loading(div_id,html_options = { })
    loading div_id, { :image_type => 'small'}.merge(html_options)
  end
  
  def large_loading(div_id,html_options = { })
    loading div_id, { :image_type => 'large'}.merge(html_options)
  end
  
  def normal_loading(div_id,html_options = { })
    loading div_id, { :image_type => 'normal'}.merge(html_options)
  end
end
